/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.cctv.esb._interface.taskfeedbackservice._0_1;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Logger;

import org.apache.commons.lang3.StringUtils;

import com.cctv.cdm.schema.playitemstatuslisttype._1.PlayItemStatusListType;
import com.cctv.cdm.schema.playitemstatuslisttype._1.PlayItemStatusListType.PlayItemStatuses.PlayItemStatus;
import com.cctv.esb.schema.taskmessages._0.CommonTaskResponseType;
import com.cctv.esb.schema.taskmessages._0.ReportTaskFeedbackRequestType.TaskFeedbackInfo;
import com.cctv.esb.schema.taskmessages._0.ReportTaskFeedbackRequestType.TaskFeedbackInfo.TaskResult;
import com.cctv.ppm.schema.progcontentreviewfeedback._0.ProgContentReviewFeedbackType;
import com.cctv.ppm.schema.progreceiptfeedback._0.ProgReceiptFeedbackType;
import com.ctvit.framework.web.context.ContextHolder;
import com.ctvit.wsservice.basedata.domain.ZcdmTMonitor;
import com.ctvit.wsservice.basedata.domain.ZppmTProconrec;
import com.ctvit.wsservice.basedata.domain.ZppmTProstock;
import com.ctvit.wsservice.basedata.service.TaskFeedbackService;

/**
 * This class was generated by Apache CXF 3.1.4 2016-01-05T16:08:50.755+08:00
 * Generated source version: 3.1.4
 * 
 */

@javax.jws.WebService(serviceName = "TaskFeedbackService", portName = "TaskFeedbackServiceHttpPort", targetNamespace = "http://cctv.com/PPM/service/TaskFeedbackService", endpointInterface = "com.cctv.esb._interface.taskfeedbackservice._0_1.TaskFeedback")
public class TaskFeedbackServiceHttpPortImpl implements TaskFeedback {

	private static final Logger LOG = Logger.getLogger(TaskFeedbackServiceHttpPortImpl.class.getName());

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.cctv.esb._interface.taskfeedbackservice._0_1.TaskFeedback#getServiceInfo
	 * (com.cctv.esb.schema.monitor._0.GetServiceInfoRequestType
	 * getServiceInfoRequest )*
	 */
	public com.cctv.esb.schema.monitor._0.GetServiceInfoResponseType getServiceInfo(
			com.cctv.esb.schema.monitor._0.GetServiceInfoRequestType getServiceInfoRequest) {
		LOG.info("Executing operation getServiceInfo");
		System.out.println(getServiceInfoRequest);
		try {
			com.cctv.esb.schema.monitor._0.GetServiceInfoResponseType _return = null;
			return _return;
		} catch (java.lang.Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.cctv.esb._interface.taskfeedbackservice._0_1.TaskFeedback#
	 * reportTaskFeedback(com.cctv.esb.schema.messagehead._0.RequestHeadType
	 * requestHead
	 * ,)com.cctv.esb.schema.taskmessages._0.ReportTaskFeedbackRequestType
	 * reportTaskFeedbackRequest )*
	 */
	public com.cctv.esb.schema.taskmessages._0.CommonTaskResponseType reportTaskFeedback(
			com.cctv.esb.schema.messagehead._0.RequestHeadType requestHead,
			com.cctv.esb.schema.taskmessages._0.ReportTaskFeedbackRequestType reportTaskFeedbackRequest) {
		LOG.info("Executing operation reportTaskFeedback");
		System.out.println(requestHead);
		System.out.println(reportTaskFeedbackRequest);
		com.cctv.esb.schema.taskmessages._0.CommonTaskResponseType _return = null;
		ZcdmTMonitor zcdmTMonitor = null;// 备播监控信息表
		ZppmTProconrec zppmTProconrec = null;// E2E:节目内审记录表
		List<ZcdmTMonitor> ListZcdmTMonitor = new ArrayList<ZcdmTMonitor>();
		TaskFeedbackInfo taskFeedbackInfo = reportTaskFeedbackRequest.getTaskFeedbackInfo().get(0);
		TaskResult taskResult = taskFeedbackInfo.getTaskResult();// 结果类型
		String objType = taskFeedbackInfo.getObjectType();// 对象类型
		try {
			TaskFeedbackService taskFeedbackService = ContextHolder.getBean(TaskFeedbackService.class); // 操作类
			if (objType.equals("PlayItemStatusList")) {
				// 获取数据
				PlayItemStatusListType playItemStatusListType = taskResult.getPlayItemStatusListRequest();
				List<PlayItemStatus> playItemStatues = playItemStatusListType.getPlayItemStatuses().getPlayItemStatus();
				for (int i = 0; i < playItemStatues.size(); i++) {
					zcdmTMonitor = new ZcdmTMonitor();
					PlayItemStatus playItemStatus = playItemStatues.get(i);
					zcdmTMonitor.setZProItemCd(playItemStatus.getBroadcastListItemID()); // 播出单条目标识
					zcdmTMonitor.setZSystemId(playItemStatusListType.getSystemID());// 发送系统标识（发送方）
					zcdmTMonitor.setZProCode(playItemStatusListType.getBroadcastListID());// 节目播出单标识
					zcdmTMonitor.setZChanlCd(playItemStatusListType.getChannelCode());// 频道代码
					zcdmTMonitor.setZPlayDate(playItemStatusListType.getPlayDate().toGregorianCalendar().getTime());// 播出日期
					zcdmTMonitor.setZProCode(playItemStatus.getProgramCode());// 节目代码
					zcdmTMonitor.setZAudVer(playItemStatus.getAudioLanguage().getLangCode());// 音频语言版本
					zcdmTMonitor.setZCapVer(playItemStatus.getSubtitleLanguage().getLangCode());// 字幕语言版本
					zcdmTMonitor.setZProItemSta(playItemStatus.getPlayItemStatus());// 播出条目状态
					Date date = new Date();
					zcdmTMonitor.setZReceiveDate(date);
					zcdmTMonitor.setZReceiveTime(new SimpleDateFormat("HH:mm:ss").format(date));
					zcdmTMonitor.setZStatus("0");
					ListZcdmTMonitor.add(zcdmTMonitor);
				}
				_return = setResponseMessage(taskFeedbackService.save(ListZcdmTMonitor));
			} else if (objType.equals("ProgContentReviewFeedback")) {
				ProgContentReviewFeedbackType progContentReviewFeedbackType = taskResult.getProgContentReviewFeedback();
				zppmTProconrec = new ZppmTProconrec();
				zppmTProconrec.setZProcode(progContentReviewFeedbackType.getProgramCode());// 节目代码
				zppmTProconrec.setZTaskId(taskFeedbackInfo.getTaskID());
				zppmTProconrec.setZAudVer(progContentReviewFeedbackType.getAudioLanguage().getLangCode());// 音频语言版本
				zppmTProconrec.setZCapVer(progContentReviewFeedbackType.getSubtitleLanguage().getLangCode());// 字幕语言版本
				zppmTProconrec.setZConInchg(progContentReviewFeedbackType.getContentCensorIncharge());// E2E:内审负责人ID
				zppmTProconrec.setZConLevel(progContentReviewFeedbackType.getContentCensorLevel().getLevelCode().longValue());// E2E:节目内审级别
				zppmTProconrec.setZConTimes(progContentReviewFeedbackType.getContentCensorTimes().longValue());// E2E:内审次数
				zppmTProconrec.setZConStage(progContentReviewFeedbackType.getContentCensorStage());// E2E:内审阶段状态
				zppmTProconrec.setZConStgtm(new Timestamp(progContentReviewFeedbackType.getCensorStageTime().toGregorianCalendar().getTimeInMillis()));// E2E:内容阶段审看完成时间
				zppmTProconrec.setZStatus("0");
				zppmTProconrec.setZCreateTime(new Timestamp(GregorianCalendar.getInstance().getTimeInMillis()));
				try {
					_return = setResponseMessage(taskFeedbackService.saveProconrec(zppmTProconrec));
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (StringUtils.equals("ProgReceiptFeedback", objType)) {// 入库任务
				ZppmTProstock zppmTProstock = new ZppmTProstock();
				ProgReceiptFeedbackType progReceiptFeedbackType = taskResult.getProgReceiptFeedback();

				zppmTProstock.setZTaskId(taskFeedbackInfo.getTaskID());
				zppmTProstock.setZFinishedResult(String.valueOf(progReceiptFeedbackType.getFinishedProgResult()));
				zppmTProstock.setZFinishedTime(new Timestamp(progReceiptFeedbackType.getFinishedProgTime().toGregorianCalendar().getTimeInMillis()));// 入库完成时间
				zppmTProstock.setZStatus("0");
				zppmTProstock.setZCreateTime(new Timestamp(GregorianCalendar.getInstance().getTimeInMillis()));

				_return = setStockResponseMessage(taskFeedbackService.saveProRecStock(zppmTProstock));

			}
			return _return; // 反馈信息
		} catch (java.lang.Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex);
		}
	}

	private CommonTaskResponseType setStockResponseMessage(int i) {
		CommonTaskResponseType _return = new CommonTaskResponseType();
		String message = "", code = "";
		if (i == 0) {
			code = "000";
			message = "操作已成功!";
		} else if (i == -1) {
			code = "050";
			message = "入库任务号不存在!";
		} else if (i == -2) {
			code = "051";
			message = "任务已经入库，拒绝接收!";
		}
		List<CommonTaskResponseType.TaskResponseInfo> list = _return.getTaskResponseInfo();
		list.add(new CommonTaskResponseType.TaskResponseInfo());
		list.get(0).setDescription(message);
		list.get(0).setStatusCode(code);
		return _return;
	}

	/**
	 * 
	 * @ps:设置返回信息
	 * @param i
	 * @return
	 */
	private CommonTaskResponseType setResponseMessage(int i) {
		CommonTaskResponseType _return = new CommonTaskResponseType();
		String message = "", code = "";
		if (i == 0) {
			code = "000";
			message = "操作已成功!";
		} else if (i == -1) {
			code = "050";
			message = "任务号不存在!";
		} else if (i == -2) {
			code = "051";
			message = "内审完成!";
		}
		List<CommonTaskResponseType.TaskResponseInfo> list = _return.getTaskResponseInfo();
		list.add(new CommonTaskResponseType.TaskResponseInfo());
		list.get(0).setStatusCode(code);
		list.get(0).setDescription(message);
		return _return;
	}

}
